package com.agile.leetcode.jdk8.functional;

import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import java.util.function.Consumer;
import java.util.function.Supplier;

/**
 * @Author ChenZhangKun
 * @Date 2020/9/1 15:06
 */
public class FunctionDemo1 {
    public static void main(String[] args) throws IOException {
        method("czk",(String name)->{
            // 拿到name后需要做的事
            System.out.println(name);
        });
        method("czk",()->"a");
        method("czk",(String name)->{
            System.out.println(name);
        },(String name)->{
            System.out.println(name+"nzq");
        });
        method(new String[]{"czk","nzq","nzq"},(String name)->{
            System.out.println(name+"1");
        },(String name)->{
            System.out.println(name+"2");
        });
        method();
    }

    /**
     * 传入函数接口
     * @param name
     * @param consumer
     */
    public static void method(String name, Consumer<String> consumer){
        consumer.accept(name);
    }
    public static void method(String name, Supplier<String> supplier){
        String s = supplier.get();
        System.out.println(name+" "+s);
    }
    public static void method(String name,Consumer<String> consumer1,Consumer<String> consumer2){
        consumer1.andThen(consumer2).accept(name);
    }
    public static void method(String[] name,Consumer<String> consumer1,Consumer<String> consumer2){
        for (String s : name) {
            consumer1.andThen(consumer2).accept(s);
        }
    }
    public static void method() throws IOException {
        // 得到上下文类加载器
        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        // 拿到资源
        Enumeration<URL> resources = contextClassLoader.getResources("java/util/function/Consumer.class");
        while (resources.hasMoreElements()){
            System.out.println(resources.nextElement());
        }
    }
}
